package com.detrum.sportcamera.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.detrum.sportcamera.R;

/**
 * Created by abc on 2018/5/22.
 */

public class CutDownAdapter extends BaseAdapter {
    private LayoutInflater layoutInflater;
    private String[]names={"0s","5s","10s","15s"};
    private int flag;

    public CutDownAdapter(Context context, int flag) {
        layoutInflater = LayoutInflater.from(context);
        this.flag = flag;
    }

    public void setPosition(int flag){
        this.flag = flag;
        this.notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return names.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CutDownHolder holder;
        if(convertView==null){
            convertView = layoutInflater.inflate(R.layout.ratios_item,parent,false);
            holder = new CutDownHolder();
            holder.name = convertView.findViewById(R.id.name);
            holder.select = convertView.findViewById(R.id.select);
            convertView.setTag(holder);
        }else{
            holder = (CutDownHolder) convertView.getTag();
        }
        holder.name.setText(names[position]);
        if(position==flag){
            holder.select.setImageResource(R.mipmap.select_2);
        }else{
            holder.select.setImageResource(R.mipmap.select_1);
        }
        return convertView;
    }

    class CutDownHolder{
        ImageView select;
        TextView name;
    }
}
